package com.huike.web.controller.review;


import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.review.pojo.Review;
import com.huike.review.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;

/**
 * 该Controller主要是为了复习三层架构以及Mybatis使用的，该部分接口已经放开权限，可以直接访问
 * 同学们在此处编写接口通过浏览器访问看是否能完成最简单的增删改查
 */
@RestController
@RequestMapping("/review")
public class MybatisReviewController extends BaseController {

    @Autowired
    private ReviewService reviewService;

    /**=========================================================新增数据============================================*/

@PostMapping("/saveData")
public AjaxResult InsertData(@RequestBody Review review){
    reviewService.insert(review);
    return AjaxResult.success("保存成功");
}


    @GetMapping("/saveData/{name}/{age}/{sex}")
    public AjaxResult insertData(@PathVariable("name") String name,@PathVariable("age") Integer age,@PathVariable("sex") String sex){
        Review review = new Review();
        review.setName(name);
        review.setAge(age);
        review.setSex(sex);
        reviewService.insert(review);
        return AjaxResult.success("保存成功");
    }

    /**=========================================================删除数据=============================================*/
    @DeleteMapping("/remove/{id}")
    public AjaxResult delectById(@PathVariable("id") Long id){
        Review review = new Review();
        review.setId(id);
        reviewService.delect(review);

        return AjaxResult.success("删除成功");
    }
    /**=========================================================修改数据=============================================*/

    @PostMapping("/update")
    public AjaxResult update(@RequestBody Review review){

        reviewService.updateReview(review);
        return AjaxResult.success("修改成功");
    }
    /**=========================================================查询数据=============================================*/


    @GetMapping("/getById")
    public AjaxResult selectById(@PathParam("id") Long id){
        Review review = new Review();
        review.setId(id);
        Review select = reviewService.select(review);
        return AjaxResult.success("查询成功",select);
    }

    /*接口名：
					/review/getDataByPage?pageNum=1&pageSize=10
				请求方式：
					GET请求
				传入参数：
					pageNum:当前页
					pageSize:每页显示条数
				返回值：
					{
					  "total": 16,
					  "rows": [
						{
						  "createBy": "1",
						  "createTime": "2022-04-17 18:53:09",
						  "updateBy": "1",
						  "updateTime": "2022-04-17 18:53:09",
						  "id": 1,
						  "name": "张三",
						  "age": 18,
						  "sex": "男"
						}...
					  ],
					  "code": 200,
					  "msg": "查询成功",
					  "params": null
					}*/


}